/*
 * Copyright 2015-2016 fududu.org Team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.fududu.oauth2;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * The OAuth2.0 request top interface.
 *
 * @author Fuchun
 * @since 1.0
 */
public interface OAuth2Request extends Serializable {

    static String encodeUrl(String url) {
        try {
            return java.net.URLEncoder.encode(url, "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            // ignore this exception, assert false
        }
        return null;
    }

    static String decodeUrl(String url) {
        try {
            return java.net.URLDecoder.decode(url, "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            // ignore this exception, assert false
        }
        return null;
    }

    /**
     * The query string joiner.
     */
    Joiner.MapJoiner QS_JOINER = Joiner.on("&").useForNull("").withKeyValueSeparator("=");

    /**
     * The query string splitter.
     */
    Splitter.MapSplitter QS_SPLITTER = Splitter.on("&").trimResults().withKeyValueSeparator("=");

    /**
     * Returns the client identifier of the authorization/authentication request.
     */
    String getClientId();

    /**
     * Returns the client secret of the authorization/authentication request.
     */
    String getClientSecret();

    /**
     * Returns the redirection endpoint URI of the authorization/authentication request.
     */
    String getRedirectUri();

    /**
     * Returns the scope of the authorization/authentication request.
     */
    String getScope();

    /**
     * Return the custom parameters of the authorization/authentication request.
     */
    Map<String, String> getCustomParams();

    /**
     * Returns the authorization/authentication request query string.
     */
    String getQueryString();
}
